feat: 动态工具插件化——引入可扩展的 DynamicToolRegistry#3
Merged
Conversation
- Introduce DynamicToolRegistry class with register/unregister/getDefinition/
getAllNames/buildEnabledSpecs/buildDefaultEnabledByName methods
- Export singleton dynamicToolRegistry pre-loaded with image_generate builtin
- New tools can now be added via dynamicToolRegistry.register({...}) without
modifying core types or union definitions
- Update localSettings to use Record<string, boolean> for enabledByName
(open to any registered tool name, not just closed union)
- Keep all existing exports as backward-compatible wrappers (marked @deprecated)
- Add 6 new unit tests for DynamicToolRegistry (total: 36 tests passing)
Contributor
Author
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
将动态工具系统从"写死的联合类型 + 静态记录"重构为可扩展的注册表模式。
之前
BuiltinDynamicToolName = "image_generate"是封闭联合,新增工具必须修改核心类型。重构后新增工具只需:
注册后工具自动出现在设置的启用/禁用列表中,并在下一次 Codex 会话启动时被注入。
Scope
packages/shared/src/dynamicTools.ts— 核心重构:DynamicToolRegistry类 + 单例 + builtin 自注册 + 旧导出兼容层packages/shared/src/localSettings.ts—enabledByName类型从Record<BuiltinDynamicToolName, boolean>放宽为Record<string, boolean>packages/shared/src/__tests__/dynamicTools.test.ts— 新增 6 个注册表测试,总计 36 个测试通过Verification
pnpm run format:checkpnpm run lintpnpm run typecheck(4 个子包全部通过)pnpm run test— 36 tests passedScreenshots or Recordings
N/A(无 UI 变更)
Notes
BUILTIN_DYNAMIC_TOOL_DEFINITIONS、buildBuiltinDynamicToolSpecs、filterEnabledBuiltinDynamicToolNames、normalizeBuiltinDynamicToolName)标记@deprecated但仍可用,调用侧无需立即修改。DynamicToolRegistry是纯内存结构,渲染层和主进程各自维护独立实例;当前dynamicToolRegistry单例在模块加载时注册内置工具。Link to Devin session: https://app.devin.ai/sessions/26c0ad2a81d3440eaa67d6f4feb3df33
Requested by: @QinQinChina